﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Data;
using PickingBusiness;

namespace Picking_Winform
{
    public class ConfigInfo
    {
        public static int MaxWorkerCount = 0;
        public static int MinWorkerCount = 1;
        public static int MaxLightAddress = 0;
        public static int MinLightAddress = 0;
        public static string IsPrint = "T";
        public static string LineName = string.Empty;
        public static string LineCode = string.Empty;

        public static string CmdLEDGreen = "8001";
        public static string CmdLEDYellow = "8002";
        public static string CmdLEDRed = "8003";
        public static string CmdLEDBeep = "8004";

        public static string AxAiPlugIpAddress = string.Empty;
        public static short AxAiPlugPort = 0;
        public static int LightNumInOneCommand = 10;

        public static void InitConfigInfo()
        {
            AxAiPlugIpAddress = ConfigurationManager.AppSettings["AxAiPlugIpAddress"].ToString().Trim();
            AxAiPlugPort = short.Parse(ConfigurationManager.AppSettings["AxAiPlugPort"].ToString().Trim());

            CmdLEDGreen = ConfigurationManager.AppSettings["CmdLEDGreen"].ToString().Trim();
            CmdLEDYellow = ConfigurationManager.AppSettings["CmdLEDYellow"].ToString().Trim();
            CmdLEDRed = ConfigurationManager.AppSettings["CmdLEDRed"].ToString().Trim();
            CmdLEDBeep = ConfigurationManager.AppSettings["CmdLEDBeep"].ToString().Trim();

            string lightNum = ConfigurationManager.AppSettings["LightNumInOneCommand"].ToString().Trim();

            int lightNumTemp = 0;

            if (int.TryParse(lightNum, out lightNumTemp))
            {
                if (lightNumTemp > 0)
                {
                    LightNumInOneCommand = lightNumTemp;
                }
            }

            DataRow row = PickingBusiness.Configuration.GetCurrentUseParameters();

            LineName = row["Line_Name"].ToString();
            LineCode = row["Line_No"].ToString();
            IsPrint = row["IsPrint"].ToString();

            string workerCount = row["Picking_Worker_No"].ToString();
            string maxAddressNo = row["Max_Address_No"].ToString();
            string minAddressNo = row["Min_Address_No"].ToString();

            int workerCountTemp = 0;
            int maxLightAddressTemp = 0;
            int minLightAddressTemp = 0;

            if (int.TryParse(workerCount, out workerCountTemp))
            {
                MaxWorkerCount = workerCountTemp;
            }

            if (int.TryParse(maxAddressNo, out maxLightAddressTemp))
            {
                MaxLightAddress = maxLightAddressTemp;
            }

            if (int.TryParse(minAddressNo, out minLightAddressTemp))
            {
                MinLightAddress = minLightAddressTemp;
            }
        }
    }
}